﻿using UnityEngine;
using System.Collections;
using AssetBundleHelper;
using HotUI;

public delegate void DelegateABObject(ABObject obj);
/// <summary>
/// 专门为Lua准备的
/// </summary>
public class LuaGameTool{
	public static void SaveData(string key,string value){
		MyPlayerPrefabs.setString(key,value);
	}
	public static string GetData(string key,string defaultstr){
		return MyPlayerPrefabs.getString(key,defaultstr	);
	}

	public static LuaView OpenStateUI(string uiname,object arg){
		return UIMgr.Instance.SetState(uiname,arg);
	}
	public static LuaView OpenDialog(string uiname,object arg)
	{
		return UIMgr.Instance.SetDialogState(uiname,arg);
	}
	public static void CloseDialog(){
		UIMgr.Instance.CloseDialog();
	}
	public static void CloseAllDialog(){
		UIMgr.Instance.CloseAllDialog();
	}
	public static void ShowFlashText(string str,float time){
		var dia = new DialogFlashText(str,time);
		var dialog = OpenDialog("dialog_flash_text",JsonUtility.ToJson(dia));
	}
	public static void LoadScene(string name,System.Action<ABObject> callback = null){
		#if UNITY_EDITOR && Resources
		UnityEngine.SceneManagement.SceneManager.LoadScene(name);
		#else
		var ab = AssetBundleDataMgr.Instance.data.getSceneAB (name);
		if(ab == null){
		UnityEngine.SceneManagement.SceneManager.LoadScene(name);
		}else{
		ab.LoadScene();
		if(callback != null)
		callback(ab);
		}
		#endif
	}

	public static void LuaLoadObject(string name,Transform parent,System.Action<ABObject> callback,string path,float despawn){
		GameTool.LoadObject(name,parent,callback,path,despawn);
	}
}
